<template>
  <div class="app-container">

    <el-dialog title="经验值明细" :visible.sync="open" width="60%" append-to-body>
<!-- 1、活动中心签到
2.活动中心任务
3.贵族特权加速（开通价格减去赠送的狗粮）
            4赠送礼物（包含背包礼物，每消费1狗粮等于1经验值）
            5订单消费（1狗粮=1经验值，只计算每天消费前三笔订单）
            6开通电台粉丝*
            0、管理员修改 -->

      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item label="来源" prop="source">
          <el-select v-model="queryParams.type" clearable size="small">
            <el-option label="活动中心签到" :value="1" />
            <el-option label="活动中心任务" :value="2" />
            <el-option label="贵族特权加速" :value="3" />
            <el-option label="赠送礼物" :value="4" />
            <el-option label="订单消费" :value="5" />
            <el-option label="开通电台粉丝" :value="6" />
            <el-option label="管理员修改" :value="7" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="userExperienceList" @selection-change="handleSelectionChange">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="来源" align="center" prop="source" >
          <template slot-scope="scope">
            <span v-if="scope.row.source===1">活动中心签到</span>
            <span v-else-if="scope.row.source===2">活动中心任务</span>
            <span v-else-if="scope.row.source===3">贵族特权加速</span>
            <span v-else-if="scope.row.source===4">赠送礼物</span>
            <span v-else-if="scope.row.source===5">订单消费</span>
            <span v-else-if="scope.row.source===6">开通电台粉丝</span>
            <span v-else-if="scope.row.source===0">管理员修改</span>
            <span v-else>未知</span>
          </template>
        </el-table-column>
        <el-table-column label="经验值变化" align="center" prop="experiencePoints" />
        <el-table-column label="当前经验值" align="center" prop="currentExperience" />
        <el-table-column label="时间" align="center" >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remarks" />
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

    </el-dialog>
  </div>
</template>

<script>
import { listUserExperience, getUserExperience, delUserExperience, addUserExperience, updateUserExperience, exportUserExperience } from "@/api/system/userExperience";

export default {
  name: "UserExperience",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 用户经验明细表格数据
      userExperienceList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        source: undefined,
      },
      userData:{}
    };
  },
  created() {
  },
  methods: {
    init(row){
      this.getList()
      this.open = true
      this.userData = row
    },
    /** 查询用户经验明细列表 */
    getList() {
      this.loading = true;
      listUserExperience(this.queryParams).then(response => {
        this.userExperienceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有用户经验明细数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportUserExperience(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>